<?php

namespace app\middleware;

use app\model\StationPrice;
use app\model\Supplier;
use app\model\SupplierPriceRule;
use app\model\User;
use Closure;
use think\facade\Cache;

class CarMiddleware
{
    public function handle(\think\Request $request, Closure $next)
    {
        $author = $request->header('authorization');
        $author = json_decode($author ?? '[]', true);
        if (!empty($author)) {
            $token = Cache::get('car_' . $author['token'] ?? '');
            if (!empty($token) && $token['verify_time'] > time()) {
                $use = app(
                    Supplier::class
                )->where('id', $token['id'])->where('state',1)->find();
                if (!empty($use)) $request->supplier = $use;
            }
        }
        return $next($request);
    }
}
